# Author:Zhang Yu
# 统计所有线程运行后的总时间
import threading
import time
class MyThread(threading.Thread):
    def __init__(self,n):
        super(MyThread,self).__init__()
        self.n = n

    def run(self):
        lock.acquire() #2.7需要加锁 3.X不需要
        global num
        num += 1
        print(num)
        lock.release()
lock = threading.Lock()

if __name__ == '__main__':
    num = 0
    t_objs = []
    start_time = time.time()
    for i in range(50):
        t1 = MyThread(i)
        t1.start()
        time.sleep(2)
        t_objs.append(t1)
    for t in t_objs:
        t.join()
    print("num:",num)
